package com.xiaoshuidi.cloud.module.rooms.repository;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaoshuidi.cloud.module.rooms.controller.admin.doorlockcdkey.vo.RoomDoorlockCdkeyPageReq;
import com.xiaoshuidi.cloud.module.rooms.mapper.RoomDoorlockCdkeyMapper;
import com.xiaoshuidi.cloud.module.rooms.pojo.RoomDoorlockCdkey;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author Feng
 * @date 2023/9/27
 */
@Repository
public class RoomDoorlockCdkeyRepository extends ServiceImpl<RoomDoorlockCdkeyMapper, RoomDoorlockCdkey> {

    /**
     * 分页查询
     *
     * @param req
     * @return
     */
    public Page<RoomDoorlockCdkey> page(RoomDoorlockCdkeyPageReq req) {
        Page<RoomDoorlockCdkey> page = Page.of(req.getPageNo(), req.getPageSize());
        LambdaQueryWrapper<RoomDoorlockCdkey> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(req.getApartmentId() != null, RoomDoorlockCdkey::getApartmentId, req.getApartmentId())
                .orderByDesc(RoomDoorlockCdkey::getId);
        return this.page(page, wrapper);
    }

    /**
     * 根据门店ID 获取配置
     *
     * @param apartmentId
     * @return
     */
    public List<RoomDoorlockCdkey> listByApartmentId(Long apartmentId) {
        LambdaQueryWrapper<RoomDoorlockCdkey> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(RoomDoorlockCdkey::getApartmentId, apartmentId);
        return this.list(wrapper);
    }
}
